home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / ae / code / ax3.00 / searchstring.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-03  |  4.5 KB  |  185 lines

  1. #include "bbs.h"
  2.  
  3. extern BOOL DupeYes;/* Inserted By the Hodge */
  4. extern int NumFiles;
  5. int Dupy=0;
  6.  
  7. static UBYTE *myzip;
  8. static void ClearZip(void);
  9. #define ln(x,y) current=myzip+(y*100)+x;
  10.  
  11. static int zippy(char *fname, char *search_string)
  12. {
  13.    FILE *fi;
  14.    UBYTE *current;
  15.    char image[102];
  16.    register int found=0;
  17.    int x=1;
  18.    int GI1;
  19.    myzip=AllocMem(10000L,MEMF_CLEAR|MEMF_PUBLIC);
  20.    ln(1,1);
  21.    strupr(search_string);
  22.    fi=fopen(fname,"r");
  23.    if(fi==NULL) { FreeMem(myzip,10000L); return(0); }
  24.    while(fgets(image,96,fi)!=NULL)
  25.    {
  26. if(CheckInput()) {
  27.             GI1=ReadChar(1L);
  28.             switch(GI1) {
  29.                 case '\023':    /* ctrl-s */
  30.                     GI1=ReadChar(KEYBOARD_TIMEOUT);
  31.                     if(GI1<0) {
  32.                         fclose(fi);
  33.                               FreeMem(myzip,10000L);
  34.                         return(GI1);
  35.                     }
  36.                     break;
  37.                 case '\003':    /*  ctrl-c */
  38.                     fclose(fi);
  39.                     AEPutStr("**Break\r\n");
  40.                          FreeMem(myzip,10000L);
  41.                     return(FAILURE);
  42.                     break;
  43.                 }
  44.             }
  45.      StripReturn(image);
  46.      if(image[0]!=' ')
  47.      {
  48.        ln(1,x); *current='\0';
  49.        if(found)
  50.        {
  51.          found=1; 
  52.          while(1) { ln(1,found); if(*current=='\0') break; AEPutStr(current); AEPutStr("\r\n"); found++;
  53.                     GI1=FlagPause(1);
  54.                     if(GI1<0) {
  55.                    fclose(fi);
  56.                        FreeMem(myzip,10000L);
  57.                    return(GI1); 
  58.                     }
  59.          }
  60.         }
  61.        found=0; x=1; ln(1,x);
  62.      }
  63.      strcpy(current,image);
  64.      strupr(image); if(strstr(image,search_string)) found=1;
  65.       x++;
  66.      ln(1,x); 
  67.   }
  68.     ln(1,x); *current='\0';
  69.     if(found)
  70.        {
  71.          found=1; while(1) { ln(1,found); if(*current=='\0') break; AEPutStr(current); AEPutStr("\r\n"); found++; 
  72.                     GI1=FlagPause(1);
  73.                     if(GI1<0) {
  74.                    fclose(fi); FreeMem(myzip,10000L);
  75.                    return(GI1); 
  76.                     }
  77.          }
  78.        }
  79.    
  80.    fclose(fi);
  81.    AEPutStr("\r\n");
  82.    FreeMem(myzip,10000L);
  83.    return(SUCCESS);
  84. }
  85.  
  86. static void ClearZip(void)
  87. {
  88.    register int i;
  89.    UBYTE *current;
  90.  
  91.    for(i=1;i<20;i++) { ln(1,i); *current='\0'; }
  92. }
  93.  
  94.  
  95. /***************************************************************************\
  96. *                                                                           *
  97. *                          int SearchString(void)                           *
  98. *                                                                           *
  99. \***************************************************************************/
  100.  
  101. int SearchString(void)
  102. {
  103. int stat,FLLoop,mystat;
  104. char str[200],ss[80],ray[200];
  105. char tempfile[256];
  106. int fcopy = FALSE;
  107.  
  108. LineCount=gnsflag=0;
  109.  
  110.  AEPutStr("\r\n");
  111.  if(MaxDirs==0) {
  112.         MyError(5); //Sorry();
  113.         return(FAILURE);
  114.     }
  115.  
  116.  Dupy=0;
  117.  mystat=CommandSplit();
  118.  if(mystat>1) { stccpy(ss,Command[1],80); goto Skip1; }
  119.  
  120.  AEPutStr("Enter string to search for: ");
  121.  stat=LineInput("",ss,78,KEYBOARD_TIMEOUT);
  122.  if(stat<0) { return(NO_CARRIER); }
  123.  if(strlen(ss)==0) { AEPutStr("\r\n"); return(SUCCESS); }
  124.  
  125. Skip1:
  126.  (void)strupr(ss);
  127.  if(mystat>2)
  128.         stat=GetDirSpan(Command[2]);
  129.  
  130.  else    stat=GetDirSpan("\0");      /* chg to "A' to search all dirs */
  131.  
  132.  if(stat==FAILURE) return(SUCCESS);
  133.  
  134.  gnsflag=CheckForNS(MAINMENU_Li);
  135.  
  136.  if(strlen(ss)>0) {
  137.  
  138.         FLLoop=StartDir;
  139.         while(FLLoop<=DirScan) {
  140.             strcpy(str,Conference_Location);   /* get BBS conf locale dir */
  141.             if(DirScan!=(-1)) {                /* add 'DIR' */
  142. //(RTS) buff copy
  143.          if(FLLoop == MaxDirs) {    /* at upload dir */
  144.             strcat(str,"DIR");
  145.                 sprintf(ray,"%d",FLLoop);
  146.                strcat(str,ray);
  147.             sprintf(ray,"Scanning directory %d\r\n",FLLoop);
  148.             AEPutStr(ray);
  149.           /*  sprintf(tempfile,"T:tdir.%d",Cmds->AcLvl[LVL_NODE_NUMBER]);
  150.             /* now copy to T: and use the T: */
  151.             if((FileCopy(str,tempfile))) {
  152.                  strcpy(str,tempfile);
  153.                  fcopy = TRUE;
  154.             }
  155.           */
  156.          } else {
  157.  
  158.                 strcat(str,"DIR");
  159.                 sprintf(ray,"%d",FLLoop);      /* add dir Number */
  160.                 strcat(str,ray);               /* add path & name */
  161.                 sprintf(ray,"Scanning directory %d\r\n",FLLoop);
  162.                 AEPutStr(ray);
  163.         }
  164.               LineCount++;
  165.         } 
  166.              if(DirScan==-1) {
  167.                 strcat(str,"hold/held");
  168.                 AEPutStr("Scanning directory HOLD\r\n");
  169.             }
  170.             stat=zippy(str,ss);
  171.             if(stat<0) {
  172.                 AEPutStr("\r\n");
  173.              if(fcopy)      DeleteFile(tempfile);  //(RTS)
  174.                 return(stat);
  175.             }
  176.           
  177.           FLLoop +=1;
  178.         //if(DirScan!=-1) FLLoop+=1;
  179.         }
  180.     }
  181.  AEPutStr("\r\n");
  182.  if(fcopy)      DeleteFile(tempfile);  //(RTS)
  183.  return(SUCCESS);
  184. }
  185.